<?php

class Core_Backend_Component_Subject_View_Content_Edit extends Core_Backend_Component_Subject_View_Content_Create {

    protected function buildToolbar($toolbar) {
        parent::buildToolbar($toolbar);
        if($this->getIdentity()->isInRole('subject_manager') && $this->getModel()->getStatus()=="pending"){
        $group = $toolbar->createGroup('publish');
        $group->addButton($this->__('share.button.publish'))
                    ->bindEvent('click', "submitPublish('" . $this->getForm()->getId() . "', '" . $this->getUrl(array('ids'=>array($this->getModel()->getId())), 'publish') . "')");
        $group->addButton($this->__('share.button.forbid'))
                    ->bindEvent('click', "submitForbid('" . $this->getForm()->getId() . "', '" . $this->getUrl(array('ids'=>array($this->getModel()->getId())), 'forbid') . "')");
        }
        if($this->getIdentity()->isInRole('subject_manager') && $this->getModel()->getStatus()=="published"){
        $group = $toolbar->createGroup('forbid');
        $group->addButton($this->__('share.button.forbid'))
                    ->bindEvent('click', "submitForbid('" . $this->getForm()->getId() . "', '" . $this->getUrl(array('ids'=>array($this->getModel()->getId())), 'forbid') . "')");
        }
    }

    protected function buildForm($form) {
        parent::buildForm($form);
        $form->addHiddenField('ids', 'ids[]', $this->getModel()->getId());
        $form->getInput('account_ids')->setValue($this->getModel()->getAccountRelation());
        $form->addTextareaField($this->__('share.label.introduction'), 'introduction', 'content[introduction]', TRUE)
                ->addValidateRule('required');
        $form->addTextareaField($this->__('share.label.content'), 'detail', 'content[detail]', TRUE)
                ->addValidateRule('required');
        $form->bindData($this->getModel()->toArray());
    }
}